<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>序列化和反序列化</title>
	</head>
	<body>
		<script>
		//序列化：把对象转换为json格式字符串
		//json格式字符串：属性名必须用双引号，字符串类型也必须用双引号
		
			//普通对象
			const obj = {
				id:10002,
				name:'xiaoming',
				age:16,
				address:'XX省XX市'
			}
			console.log("========序列化========")
			//序列化
			const jsonStr = JSON.stringify(obj)
			console.log(jsonStr)
			
			console.log("========反序列化========")
			const jsonObj = `{
				"id":10002,
				"name":"xiaoli",
				"age":16,
				"address":"XX省XX市"
			}`
			
			//反序列化
		const Str = JSON.parse(jsonObj)
		console.log(Str)
		
		</script>
	</body>
</html>